package com.android.lovingpet.adopt.host.behost;

import android.util.Log;

import com.android.lovingpet.common.Back;
import com.android.lovingpet.util.HttpUtil;
import com.android.lovingpet.util.MyHttp;
import com.android.lovingpet.util.URLStore;
import com.android.lovingpet.util.Utility;

import java.io.IOException;
import java.util.HashMap;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;

/**
 * Created by ikata on 2018/4/27.
 */

public class BeHostModel {

    public void beHost(HashMap<String,String> params, Back back)
    {
        MyHttp.getInstance().postAsync(Utility.getJSessionId(), URLStore.HOST_BEHOST, params, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                back.onFailure(MyHttp.getFailureMeg());
            }
            @Override
            public void onResponse(Call call, Response response) throws IOException {
                String responseData = response.body().string();
                int code = HttpUtil.getCode(responseData);
                Log.d("有没有阿","1");
                if (code == 0) {
                    Log.d("有没有阿","2");
                    back.onSuccess(null);
                }
                else
                {
                    back.onFailure(MyHttp.getCodeString(code));
                }
            }
        });
    }

}
